#ifndef OPENNAVMAP_H_
#define OPENNAVMAP_H_

#include <FBase.h>
#include <FLocations.h>
#include <FGraphics.h>
#include <Opennav.h>
#include <string>

class OpennavMapSection {
public:
	OpennavMapSection();
	~OpennavMapSection();
	result Construct(Osp::Graphics::Canvas* map, opennav::Transformation& transformation, Osp::Locations::Coordinates& mapCenter);
	void Draw(Osp::Graphics::Canvas& canvas, const Osp::Graphics::Point& pan, float zoom);
	const Osp::Locations::Coordinates& GetCenter() const;
	void TransformCoordinatesToPixels(const Osp::Locations::Coordinates& coord, Osp::Graphics::Point& convertedPoint) const;
	void TransformPixelsToCoordinates(const Osp::Graphics::Point& point, Osp::Locations::Coordinates& convertedCoordinates) const;
	void TransformCenter(const Osp::Graphics::Point& pan, float zoom, Osp::Locations::Coordinates& convertedMapCenter, float& zoomLevel) const;
private:
	Osp::Graphics::Canvas* __pMap;
	opennav::Transformation __transformation;
	Osp::Locations::Coordinates __center;
};

class OpennavMap {
public:
	OpennavMap();
	~OpennavMap();
	result Construct(opennav::Map* map);
	OpennavMapSection* CreateSection(Osp::Locations::Coordinates& mapCenter, float zoomLevel, float azimuth, Osp::Graphics::Dimension& size);
	void FindCountry(Osp::Base::String& name, opennav::SearchCountryResult& result);
	void GetResult(int n, opennav::SearchCountryResult* result, opennav::Country& country);
	void FindCity(Osp::Base::String& name, int countryId, opennav::SearchCityResult& result);
	void GetResult(int n, opennav::SearchCityResult* result, opennav::City& city);
	void FindRoad(Osp::Base::String& name, int cityId, opennav::SearchRoadResult& result);
	void GetResult(int n, opennav::SearchRoadResult* result, opennav::Road& road);

	void GetCountry(int countryId, opennav::Country& country);
	void GetCity(int cityId, opennav::City& city);
	void GetRegion(int regionId, opennav::Region& region);

	bool ReverseGeocode(Osp::Locations::Coordinates& coordinate, opennav::Road& road, opennav::RoadSegment& segment, opennav::RoadJunction& next_junction, Osp::Locations::Coordinates& c);
private:
	opennav::Map* __pMap;
	Osp::Base::Runtime::Mutex* __pLock;
};

#endif /* OPENNAVMAP_H_ */
